package com.ybear.ybcomponent.widget.menu;

import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import com.ybear.ybcomponent.ItemStyleBuild;
import com.ybear.ybcomponent.RedDotStyleBuild;

public class MenuItem {
    private Drawable icon;
    private Drawable iconOfSelect;
    private String text;
    private String textOfSelect;
    
    private final RedDotStyleBuild redDotStyleBuild = new RedDotStyleBuild();
    private final ItemStyleBuild itemStyleBuild = new ItemStyleBuild();

    public MenuItem(Drawable icon, String text, Drawable iconOfSelect, String textOfSelect) {
        this.icon = icon;
        this.iconOfSelect = iconOfSelect;
        this.text = text;
        this.textOfSelect = textOfSelect;
    }

    public MenuItem(Drawable icon, Drawable iconOfSelect) {
        this.icon = icon;
        this.iconOfSelect = iconOfSelect;
    }

    public MenuItem(Drawable icon, String text) {
        this.icon = icon;
        this.text = text;
    }

    public MenuItem(Drawable icon) {
        this.icon = icon;
    }

    public MenuItem(@NonNull Resources res,
                    @DrawableRes int icon, @StringRes int text,
                    @DrawableRes int iconOfSelect, @StringRes int textOfSelect) {
        setIcon( res, icon );
        setIconOfSelect( res, iconOfSelect );
        setText( res, text );
        setTextOfSelect( res, textOfSelect );
    }

    public MenuItem(@NonNull Resources res,
                    @DrawableRes int icon, String text,
                    @DrawableRes int iconOfSelect, String textOfSelect) {
        setIcon( res, icon );
        setIconOfSelect( res, iconOfSelect );
        setText( text );
        setTextOfSelect( textOfSelect );
    }

    public MenuItem(@NonNull Resources res, @DrawableRes int icon, @DrawableRes int iconOfSelect) {
        setIcon( res, icon );
        setIconOfSelect( res, iconOfSelect );
    }

    public MenuItem(@NonNull Resources res, @DrawableRes int icon) {
        setIcon( res, icon );
    }

    public MenuItem() { }

    @NonNull
    @Override
    public String toString() {
        return "MenuItem{" +
                "icon=" + icon +
                ", iconOfSelect=" + iconOfSelect +
                ", text='" + text + '\'' +
                ", textOfSelect='" + textOfSelect + '\'' +
                ", redDotStyleBuild=" + redDotStyleBuild +
                ", itemStyleBuild=" + itemStyleBuild +
                '}';
    }

    public Drawable getIcon() { return icon; }
    public MenuItem setIcon(Drawable icon) {
        this.icon = icon;
        return this;
    }
    @SuppressLint("UseCompatLoadingForDrawables")
    public MenuItem setIcon(@NonNull Resources res, @DrawableRes int resId) {
        this.icon = res.getDrawable( resId );
        return this;
    }

    public String getText() { return text; }
    public MenuItem setText(String text) {
        this.text = text;
        return this;
    }
    public MenuItem setText(@NonNull Resources res, @StringRes int resId) {
        this.text = res.getString( resId );
        return this;
    }

    public Drawable getIconOfSelect() { return iconOfSelect; }
    public MenuItem setIconOfSelect(Drawable iconOfSelect) {
        this.iconOfSelect = iconOfSelect;
        return this;
    }
    @SuppressLint("UseCompatLoadingForDrawables")
    public MenuItem setIconOfSelect(@NonNull Resources res, @DrawableRes int resId) {
        this.iconOfSelect = res.getDrawable( resId );
        return this;
    }

    public String getTextOfSelect() { return textOfSelect; }
    public MenuItem setTextOfSelect(String textOfSelect) {
        this.textOfSelect = textOfSelect;
        return this;
    }
    public MenuItem setTextOfSelect(@NonNull Resources res, @StringRes int resId) {
        this.textOfSelect = res.getString( resId );
        return this;
    }

    @NonNull
    public RedDotStyleBuild getRedDotStyleBuild() { return redDotStyleBuild; }
    public void setRedDotStyleBuild(RedDotStyleBuild build) {
        redDotStyleBuild.init( build );
    }

    @NonNull
    public ItemStyleBuild getItemStyleBuild() { return itemStyleBuild; }
    public void setItemStyleBuild(ItemStyleBuild build) {
        itemStyleBuild.init( build );
    }
}
